package cn.tansanqinger.service.hymenu.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;

import cn.tansanqinger.dao.sql.hymenu.HyMenuMessageDispose;
import cn.tansanqinger.pojo.HyMenu;
import cn.tansanqinger.service.hymenu.IHyMenuServer;

/**
 * 数据处理
 * @author C3H2
 * @time 2021.01
 */
@Service
public class HyMenuServerImpl implements IHyMenuServer{

	@Autowired
	private HyMenuMessageDispose dispose;
	
	@Override
	public ModelAndView selectHyMenuAll(ModelAndView mv) {
		List<HyMenu> firstHyMenus = dispose.selectFirstHyMenus();
		List<List<HyMenu>> hyMenus = new ArrayList<List<HyMenu>>();
		for (int i = 0; i < firstHyMenus.size(); i++) {
			List<HyMenu> list = dispose.selectSecondHyMenus(firstHyMenus.get(i).getHmenuId());
			Arrays.sort(list.toArray(), (m1,m2)->((HyMenu) m1).getHmenuOrder()>((HyMenu) m2).getHmenuOrder()?1:-1);
			hyMenus.add(list);
		}
		mv.addObject("menuAll", hyMenus);
		return mv;
	}
	
	
}
